package com.jic.product.impl;

import java.lang.Long;
import java.util.List;

import com.jic.product.entity.ProductSaleAreaRelation;
import com.jic.product.mapper.ProductSaleAreaRelationMapper;
import com.jic.product.service.ProductSaleAreaRelationService;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品销售区域关联表
 * @author : 
 * @email : 
 * @since : 2020-01-10 07:03:01
 * @version : v1.0.0
 */
@Service
public class ProductSaleAreaRelationServiceImpl implements ProductSaleAreaRelationService{

    @Autowired
    private ProductSaleAreaRelationMapper productSaleAreaRelationMapper;

    @Override
    public long insert(ProductSaleAreaRelation productSaleAreaRelation) {
        long flag = productSaleAreaRelationMapper.insert(productSaleAreaRelation);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return productSaleAreaRelationMapper.delete(id);
    }

    @Override
    public long update(ProductSaleAreaRelation productSaleAreaRelation) {
        return productSaleAreaRelationMapper.update(productSaleAreaRelation);
    }

    @Override
    public ProductSaleAreaRelation queryByPrimaryKey(Long id){
        return productSaleAreaRelationMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<ProductSaleAreaRelation> query(ProductSaleAreaRelation productSaleAreaRelation){
        return productSaleAreaRelationMapper.query(productSaleAreaRelation);
    }

    @Override
    public PageResult<ProductSaleAreaRelation> queryPage(ProductSaleAreaRelation productSaleAreaRelation, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<ProductSaleAreaRelation> list = productSaleAreaRelationMapper.queryPage(startIndex, pageQuery.getLimit(), productSaleAreaRelation);
        long count = productSaleAreaRelationMapper.queryPageCount(productSaleAreaRelation);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    /*
     * 通过商品id查询销售区域productSaleAreaRelationMapper
     * */
    @Override
    public List<ProductSaleAreaRelation> queryByProductId(Long productId) {
        return productSaleAreaRelationMapper.queryByProductId(productId);
    }
}